package jwr.ex7;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListEx {
	private static final String msg1 = "입력(1) 조회(2) 삭제(3) 끝내기(4)>>";
	private static final String msg2 = "이름 >> ";
	private static final String msg3 = "삭제할 번호 >> ";
	
	public static void main(String[] args) {
		ArrayList<String> al = new ArrayList<String>();
		Scanner sc = new Scanner(System.in);
		
		while(true){
			System.out.print(msg1);
			switch(sc.nextInt()){
				case 1: 
					System.out.print(msg2);
					al.add(sc.next());
					break;
				case 2:
					System.out.println(showArray(al));
					break;
				case 3:
					System.out.println(showArray(al));
					System.out.println(msg3);
					al.remove(sc.nextInt()-1);
					break;
				case 4:
					sc.close();
					System.out.println("종료되었습니다.");
					System.exit(0);
					break;
			}
			
		}
		
		
	}
	
	public static String showArray(ArrayList<String> al){
		StringBuilder result = new StringBuilder();
		for(int i = 1; i <= al.size();i++){
			result.append(i);
			result.append("번 ");
			result.append(al.get(i-1));
			result.append("\n");
		}
		
		return result.toString(); 
	}
	
}
